@extends('backend/layouts/default')
@section('title')
Danh sách bài viết
@stop
@section('content')
<h3>
    <span class="glyphicon glyphicon-pencil"></span> Danh sách baì viết
    <a href="" data-toggle="modal" data-target="#modal_newpost" class="btn btn-default btn-xs"><span
            class="glyphicon glyphicon-plus-sign"></span> Bài viết mới</a>
</h3>
<div class="box">
    <div class="box-header">
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <div class="row">
            <div class="col-ld-2 col-md-3 col-sm-3">
                <ul class="nav nav-pills nav-stacked">
                    <li <?= $data['appends']['status'] == '' ? 'class="active"' : "" ?>>
                        <a href="{{ route('lessons/admin') }}"><span class="glyphicon glyphicon-th-list"></span>
                            Tất cả
                        </a>
                    </li>
                    <li class="<?= $data['appends']['status'] == 'published' ? 'active' : '' ?>">
                        <a href="<?= route('lessons/admin', array('status' => 'published')) ?>">
                            <span class="glyphicon glyphicon-ok-sign"></span>
                            Đang hiển thị
                        </a>
                    </li>
                    <li class="<?= $data['appends']['status'] == 'submitted' ? 'active' : '' ?>">
                        <a href="<?= route('lessons/admin', array('status' => 'submitted')) ?>">
                            <span class="glyphicon glyphicon-time"></span>
                            Chờ xét duyệt
                        </a>
                    </li>

                    <li class="<?= $data['appends']['onlyTrashed'] == true ? 'active' : '' ?>">
                        <a href="<?= route('lessons/admin', array('onlyTrashed' => true)) ?>">
                            <span class="glyphicon glyphicon-trash"></span>
                            Đã xóa
                        </a>
                    </li>
                    <li

                </ul>
            </div>
            <div class="col-ld-10 col-md-9 col-sm-9">
                <form method="get" action="" autocomplete="off" role="form" class="form-inline">
                    <input type="hidden" name="_token" value="{{ csrf_token() }}"/>

                    <div class="form-group">
                        <?= Form::select('tone', $data['tones'], Input::old('tone', $data['appends']['tone']), array('class' => 'form-control')); ?>
                    </div>
                    <div class="form-group">
                        <?= Form::select('category', $data['categories'], Input::old('category', $data['appends']['category']), array('class' => 'form-control')); ?>
                    </div>
                    <input type="submit" class="btn btn-default btn-info" name="search" value="Tìm"/>
                </form>
                <hr/>
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th width="60"></th>
                        <th class="span6">Tiêu đề</th>
                        <th class="span2">Điệu</th>
                        <th width="span2">Chuyên mục</th>
                        <th width="span2">Thành viên</th>
                        <th width="span2">Level</th>
                        <th width="100">Ngày</th>
                        <th width="100">Tác vụ</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($data['lessons'] as $lesson)
                    <tr>
                        <td><?= $lesson->id ?></td>
                        <td><?= $lesson->title ?></td>
                        <td>
                            <?= (!is_null($tone = $lesson->tone()->first()) ? $tone->title : "Chưa có giai điệu") ?>
                        </td>
                        <td>
                            <?= (!is_null($category = $lesson->category()->first()) ? $category->title : "Chưa có chuyên mục") ?>
                        </td>
                        <td><?= $lesson->username ?></td>
                        <td><?= $lesson->level ?></td>
                        <td><?= $lesson->created_at->diffForHumans() ?></td>
                        <td>@if ( Sentry::getUser()->hasAnyAccess(['lesson','lesson.edit']) )
                            <a href="{{ route('update/lessons/admin', $lesson->id) }}" class="btn btn-xs btn-default">@lang('button.edit')</a>
                            @endif
                            @if ( Sentry::getUser()->hasAnyAccess(['lesson','lesson.delete']) )
                            <a href="{{ route('delete/lessons/admin', $lesson->id) }}" class="btn btn-mini btn-danger">@lang('button.delete')</a>
                            @endif
                        </td>
                    </tr>
                    @endforeach
                    </tbody>
                </table>
                {{ $data['lessons']->links() }}
            </div>
        </div>
    </div>
</div>
@stop